package repo;

import entity.Phase;
import util.RandomArray;

import java.util.ArrayList;

/**
 * @author Ayase
 * @date 2020/8/9-22:17
 */
public class PhaseDB {
    private static String[][] passages = {
        {"Losing your ability to think and remember is pretty scary. We know the risk of","dementia","increases with age. But if you have memory slips， you probably needn’t worry."},
        {"The brain ages just like the rest of the body. Certain parts ","shrink","， especially areas in the brain that are important to learning， memory and planning."},
        {"Living in an urban area with green spaces has a long-lasting positive impact on people’s mental well-being， a study has suggested， UK researchers found moving to a green space had a sustained ","positive"," effect."},
        {"iophysicist alex zhavoronkov believes that aging should be considered a disease. he said that describing aging as a disease creates incentives to ","develop"," treatments."},
        {"The tools of the movement consist of a bubbling stew of new technologies that ","include"," iPods, blogs, podcasts, DVRs, customized online newspapers, and satellite radio."},
        {"Rosen and others trace the beginnings of the iMedia ","revolution"," to the invention of the TV remote, which marked the first subtle shift of media control away from broadcasters and into the hands of the average couch potato. "},
        {"A recent BBC documentary, The Town That Never Retired, sought to show the effects ofincreasing the state ","pension"," age by putting retirees back to work."},
        {"Among all the animals, the ape is most like human beings. Both people and apes have the similar brain","structure",", the similar nerve system, and the similar kind of blood."},
        {"The main part of this chapter will deal ","directly"," with the technical and artistic limitations and resources that make television unique. "},
        {"the line that separates commercial interests from literary interests in ","television"," is less distinct than in most other literary forms. "}
    };

    private static ArrayList<Phase> phases = null;

    /**
     * @MethodName init
     * @Description TODO 初始化列表
     * @Param []
     * @Return void
     * @author Ayase
     * @date 15:13
     */
    private static void init(){
        phases.clear();

        for(int i = 0 ; i < passages.length; i++){
            Phase phase = new Phase();
            phase.setPreStr(passages[i][0]);
            phase.setWord(passages[i][1]);
            phase.setPostStr(passages[i][2]);
            phases.add(phase);
        }
    }

    public static Phase[] getRandomPhase(int n){
        if(phases == null){
            phases = new ArrayList<>();
            init();
        }

        Phase[] result = new Phase[n];

        RandomArray arr = new RandomArray(n);

        arr.generateRandomArr(passages.length);

        for(int i = 0 ; i < n; i++){
            result[i] = phases.get(arr.get(i));
        }

        return result;
    }
}
